package com.opcode.nebulamobil.base.adapters;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.opcode.nebulamobil.R;
import com.opcode.nebulamobil.base.components.TextViewBase;
import com.opcode.nebulamobil.information.responses.JSONResponse;
import com.opcode.nebulamobil.information.responses.costaresponses.AppInfoResp;

/**
 * 
 * @author Okan ERDOĞAN
 *
 * Oct 22, 2014
 */
public class ServerListAdapter extends ArrayAdapter<AppInfoResp>{

	private Context context;
	private int resourceId;
	private ArrayList<AppInfoResp> arrayList;

	public ServerListAdapter(Context context, int textViewResourceId,ArrayList<AppInfoResp> objects) {
		super(context, textViewResourceId, objects);

		this.context = context;
		this.resourceId = textViewResourceId;

		this.arrayList = objects;
	}

	@SuppressLint("NewApi")
	public View getView(int position, View convertView, ViewGroup parent) {

		convertView = LayoutInflater.from(this.context).inflate(this.resourceId, null);

		AppInfoResp appInfoResp = (AppInfoResp) arrayList.get(position);
		
		TextViewBase serverName=(TextViewBase) convertView.findViewById(R.id.server_name_textview);
		TextViewBase serverIpInfoTextview=(TextViewBase)convertView.findViewById(R.id.server_ip_info_textview);
		serverName.setText(appInfoResp.getAppType());
		serverIpInfoTextview.setText(appInfoResp.getIpAddress());
		
		return convertView;
	}

	public int getCount() {
		return arrayList.size();
	}

	public void notifyDataSetChanged() {
		super.notifyDataSetChanged();
	}
	
	public void updateList(ArrayList<AppInfoResp> serverList){
		notifyDataSetChanged();
		this.arrayList=serverList;
	}
}
